<html>
<head><meta charset="utf-8"><title>variance and assoc types #71550 · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html">variance and assoc types #71550</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195867644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195867644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195867644">(Apr 30 2020 at 16:46)</a>:</h4>
<p>So <span class="user-mention" data-user-id="116266">@Santiago Pastorino</span> ...</p>



<a name="195867696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195867696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195867696">(Apr 30 2020 at 16:47)</a>:</h4>
<p><span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span></p>



<a name="195867758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195867758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195867758">(Apr 30 2020 at 16:47)</a>:</h4>
<p>I guess the first thing is to track out exactly <em>why</em> this is happening</p>



<a name="195867839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195867839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195867839">(Apr 30 2020 at 16:47)</a>:</h4>
<p>The PR that was cited is somewhat surprising</p>



<a name="195867888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195867888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195867888">(Apr 30 2020 at 16:47)</a>:</h4>
<p>but before we do even that</p>



<a name="195867939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195867939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195867939">(Apr 30 2020 at 16:47)</a>:</h4>
<p>let me check-- do you understand the bug?</p>



<a name="195867953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195867953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195867953">(Apr 30 2020 at 16:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195867839" title="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195867839">said</a>:</p>
<blockquote>
<p>The PR that was cited is somewhat surprising</p>
</blockquote>
<p>why do you say it's surprising?</p>



<a name="195868101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868101">(Apr 30 2020 at 16:48)</a>:</h4>
<p>because the intent of the PR was to fix a bug like this</p>



<a name="195868114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868114">(Apr 30 2020 at 16:48)</a>:</h4>
<p>do you know what we mean by "invariant"?</p>



<a name="195868262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868262">(Apr 30 2020 at 16:49)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nomicon/subtyping.html#variance" title="https://doc.rust-lang.org/nomicon/subtyping.html#variance">https://doc.rust-lang.org/nomicon/subtyping.html#variance</a></p>



<a name="195868264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868264">(Apr 30 2020 at 16:49)</a>:</h4>
<p>:)</p>



<a name="195868287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868287">(Apr 30 2020 at 16:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195868101" title="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195868101">said</a>:</p>
<blockquote>
<p>because the intent of the PR was to fix a bug like this</p>
</blockquote>
<p>ahh I see</p>



<a name="195868364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868364">(Apr 30 2020 at 16:50)</a>:</h4>
<p>trait objects shouldn't be covariant to its associated types I guess?</p>



<a name="195868389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868389">(Apr 30 2020 at 16:50)</a>:</h4>
<p>yeah</p>



<a name="195868418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868418">(Apr 30 2020 at 16:50)</a>:</h4>
<p>so in general associated types have to be "invariant" with respect to the input types on the trait</p>



<a name="195868422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868422">(Apr 30 2020 at 16:50)</a>:</h4>
<p>in other words</p>



<a name="195868424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868424">(Apr 30 2020 at 16:50)</a>:</h4>
<p>I'd need to read a bit more and think about it properly</p>



<a name="195868469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868469">(Apr 30 2020 at 16:50)</a>:</h4>
<p>normally we say that <code>&amp;'static u32 &lt;: &amp;'a u32</code> for any <code>'a</code></p>



<a name="195868501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868501">(Apr 30 2020 at 16:51)</a>:</h4>
<p>this is because <code>&amp;'b T &lt;: &amp;'a T</code> if <code>'b: 'a</code></p>



<a name="195868511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868511">(Apr 30 2020 at 16:51)</a>:</h4>
<p>and <code>'static: 'a</code> for all <code>'a</code></p>



<a name="195868533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868533">(Apr 30 2020 at 16:51)</a>:</h4>
<p>this in turn means that <code>Vec&lt;&amp;'static u32&gt; &lt;: Vec&lt;&amp;'a u32&gt;</code>,</p>



<a name="195868545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868545">(Apr 30 2020 at 16:51)</a>:</h4>
<p>because <code>Vec&lt;T&gt;</code> is covariant with respect to <code>T</code></p>



<a name="195868583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868583">(Apr 30 2020 at 16:51)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="195868678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868678">(Apr 30 2020 at 16:52)</a>:</h4>
<p><em>but</em> if you have <code>&lt;Vec&lt;&amp;'static u32&gt; as Iterator&gt;::Item</code> and <code>&lt;Vec&lt;&amp;'a u32&gt; as Iterator&gt;::Item</code>...</p>



<a name="195868688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868688">(Apr 30 2020 at 16:52)</a>:</h4>
<p>there is no subtyping relationship</p>



<a name="195868719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868719">(Apr 30 2020 at 16:52)</a>:</h4>
<p>(even though, in that <em>particular</em> example, it would work out ok)</p>



<a name="195868759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868759">(Apr 30 2020 at 16:52)</a>:</h4>
<p>the reason is basically because we have no idea what <code>Item</code> will expand to be</p>



<a name="195868801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868801">(Apr 30 2020 at 16:52)</a>:</h4>
<p>and just because the inputs to the trait are subtypes, doesn't mean the "output" will be</p>



<a name="195868821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868821">(Apr 30 2020 at 16:53)</a>:</h4>
<p>so...similarly...</p>



<a name="195868822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868822">(Apr 30 2020 at 16:53)</a>:</h4>
<p>as I've said, I didn't spend time on this issue, but just by looking at it wonder if this can be reduced more?</p>



<a name="195868871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868871">(Apr 30 2020 at 16:53)</a>:</h4>
<p>a good question</p>



<a name="195868898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868898">(Apr 30 2020 at 16:53)</a>:</h4>
<p>surely yes</p>



<a name="195868920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195868920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195868920">(Apr 30 2020 at 16:53)</a>:</h4>
<p>one sec</p>



<a name="195869108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869108">(Apr 30 2020 at 16:54)</a>:</h4>
<p>I can investigate that but yeah if there's something obvious to you would be good to know</p>



<a name="195869189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869189">(Apr 30 2020 at 16:55)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Bar</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">gimme</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="o">&gt;</span><span class="p">(</span><span class="w"></span>
<span class="w">  </span><span class="n">x</span>: <span class="kp">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">u32</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">y</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">Bar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">u32</span><span class="o">&gt;</span><span class="w"></span>
<span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">gimme2</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="o">&gt;</span><span class="p">(</span><span class="w"></span>
<span class="w">  </span><span class="n">x</span>: <span class="kp">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">u32</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">y</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">Bar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="kt">u32</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">gimme</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="195869232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869232">(Apr 30 2020 at 16:55)</a>:</h4>
<p>so that program compiles</p>



<a name="195869240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869240">(Apr 30 2020 at 16:55)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b4e1d158b18918744d5ecb14c149b171" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=b4e1d158b18918744d5ecb14c149b171">playground</a></p>



<a name="195869245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869245">(Apr 30 2020 at 16:55)</a>:</h4>
<p>but I don't think it should</p>



<a name="195869260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869260">(Apr 30 2020 at 16:55)</a>:</h4>
<p>I was going to say ... <code>PhantomData</code> doesn't seem to be needed</p>



<a name="195869455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869455">(Apr 30 2020 at 16:56)</a>:</h4>
<p>actually we can make it smaller still</p>



<a name="195869518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869518">(Apr 30 2020 at 16:57)</a>:</h4>
<p>we can probably make it print a dangling reference as in the issue, right?</p>



<a name="195869563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869563">(Apr 30 2020 at 16:57)</a>:</h4>
<p>so we have a repro that make things explode badly :)</p>



<a name="195869585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869585">(Apr 30 2020 at 16:57)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Bar</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">make</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nb">Box</span><span class="o">&lt;</span><span class="k">dyn</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">Bar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="kt">u32</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">panic</span><span class="o">!</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">take</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="o">&gt;</span><span class="p">(</span><span class="w"></span>
<span class="w">  </span><span class="n">_</span>: <span class="kp">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">u32</span><span class="p">,</span><span class="w"></span>
<span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span>: <span class="nb">Box</span><span class="o">&lt;</span><span class="k">dyn</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">Bar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="kt">u32</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">make</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="195869607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869607">(Apr 30 2020 at 16:57)</a>:</h4>
<p>nah</p>



<a name="195869661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869661">(Apr 30 2020 at 16:58)</a>:</h4>
<p>I mean a <em>weaponized</em> variant that explodes badly</p>



<a name="195869678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869678">(Apr 30 2020 at 16:58)</a>:</h4>
<p>is sort of by definition not minimal :)</p>



<a name="195869686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869686">(Apr 30 2020 at 16:58)</a>:</h4>
<p>for debugging we want the minimal thing</p>



<a name="195869708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869708">(Apr 30 2020 at 16:58)</a>:</h4>
<p>the key bug is that this subtyping relationship doesn't hold</p>



<a name="195869753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869753">(Apr 30 2020 at 16:58)</a>:</h4>
<p>ahh yeah, for debugging minimal but as a test to place it with the PR maybe it's good?</p>



<a name="195869809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869809">(Apr 30 2020 at 16:59)</a>:</h4>
<p>maybe -- we can worry about it then</p>



<a name="195869827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869827">(Apr 30 2020 at 16:59)</a>:</h4>
<p>in any case I'll try the repro of the issue at least locally :)</p>



<a name="195869834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869834">(Apr 30 2020 at 16:59)</a>:</h4>
<p>I'd sort of prefer to include the minimal one, and then maybe also a weaponized one</p>



<a name="195869843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869843">(Apr 30 2020 at 16:59)</a>:</h4>
<p>once fixed</p>



<a name="195869904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869904">(Apr 30 2020 at 16:59)</a>:</h4>
<p>anyway the thing is to figure out why there is no invariance here</p>



<a name="195869905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869905">(Apr 30 2020 at 16:59)</a>:</h4>
<p>ok I guess I can investigate for a bit and ask questions maybe?</p>



<a name="195869908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869908">(Apr 30 2020 at 16:59)</a>:</h4>
<p>so let me give you a few tips</p>



<a name="195869933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869933">(Apr 30 2020 at 16:59)</a>:</h4>
<p>do you have ... tips ... exactly :)</p>



<a name="195869956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195869956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195869956">(Apr 30 2020 at 17:00)</a>:</h4>
<p>there are actually.. two bits of relevant code?</p>



<a name="195870075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870075">(Apr 30 2020 at 17:00)</a>:</h4>
<p>the first one would be <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_middle/ty/relate.rs" title="https://github.com/rust-lang/rust/blob/master/src/librustc_middle/ty/relate.rs">https://github.com/rust-lang/rust/blob/master/src/librustc_middle/ty/relate.rs</a> -- the "type relating" code</p>



<a name="195870087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870087">(Apr 30 2020 at 17:00)</a>:</h4>
<p>this is like a visitor that walks down two pairs of types</p>



<a name="195870159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870159">(Apr 30 2020 at 17:00)</a>:</h4>
<p>note that it has this callback <a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L68" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L68"><code>relate_with_variance</code></a></p>



<a name="195870228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870228">(Apr 30 2020 at 17:01)</a>:</h4>
<p>so if we loop down here.. we see <a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L382-L387" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L382-L387">this code</a>, which is where it handles two <code>dyn</code> types</p>



<a name="195870287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870287">(Apr 30 2020 at 17:02)</a>:</h4>
<p>you can see that it is specifying <code>Contravariant</code> here as it relates the "predicates" of the two dyn types (<a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L384" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L384">line</a>)</p>



<a name="195870340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870340">(Apr 30 2020 at 17:02)</a>:</h4>
<p>I...have no real idea why it would choose that, actually</p>



<a name="195870378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870378">(Apr 30 2020 at 17:02)</a>:</h4>
<p>/me thinks</p>



<a name="195870390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870390">(Apr 30 2020 at 17:02)</a>:</h4>
<p>or sorry</p>



<a name="195870396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870396">(Apr 30 2020 at 17:02)</a>:</h4>
<p>that is <em>just</em> the region bound</p>



<a name="195870416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870416">(Apr 30 2020 at 17:02)</a>:</h4>
<p>i.e., a <code>dyn</code> type is really short for <code>dyn Bound + 'a</code></p>



<a name="195870433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870433">(Apr 30 2020 at 17:03)</a>:</h4>
<p>and it is <em>correct</em> that the <code>'a</code> region bound is contravariant</p>



<a name="195870456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870456">(Apr 30 2020 at 17:03)</a>:</h4>
<p>ahh right <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="195870460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870460">(Apr 30 2020 at 17:03)</a>:</h4>
<p>more interesting is the <a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L386" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L386">recursive call <code>relation.relate</code></a></p>



<a name="195870492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870492">(Apr 30 2020 at 17:03)</a>:</h4>
<p>which will I think bring you to <a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L595" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L595">the impl for <code>ExistentialPredicate</code></a></p>



<a name="195870591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870591">(Apr 30 2020 at 17:04)</a>:</h4>
<p>which will bring you ultimately <a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L240" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L240">*here*</a></p>



<a name="195870602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870602">(Apr 30 2020 at 17:04)</a>:</h4>
<p>(at least for the case of <code>Foo=Bar</code> bounds)</p>



<a name="195870620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870620">(Apr 30 2020 at 17:04)</a>:</h4>
<p>I'm sort of debating where I think the bug is here</p>



<a name="195870677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870677">(Apr 30 2020 at 17:05)</a>:</h4>
<p>but somewhere along this chain, we should have a <code>relate_with_invariance</code> sort of call</p>



<a name="195870699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870699">(Apr 30 2020 at 17:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195870460" title="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195870460">said</a>:</p>
<blockquote>
<p>more interesting is the <a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L386" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L386">recursive call <code>relation.relate</code></a></p>
</blockquote>
<p>quite possibly on <em>this line</em>, but maybe <em>also</em> other lines :)</p>



<a name="195870769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870769">(Apr 30 2020 at 17:05)</a>:</h4>
<p>to explain what I mean...</p>



<a name="195870786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870786">(Apr 30 2020 at 17:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195870677" title="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195870677">said</a>:</p>
<blockquote>
<p>but somewhere along this chain, we should have a <code>relate_with_invariance</code> sort of call</p>
</blockquote>
<p>you meant, instead of just a <code>relate</code> call?</p>



<a name="195870827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870827">(Apr 30 2020 at 17:06)</a>:</h4>
<p>yeah</p>



<a name="195870842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870842">(Apr 30 2020 at 17:06)</a>:</h4>
<p>the actual fn is <code>relate_with_variance</code> and supplying an argument of invariance</p>



<a name="195870866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870866">(Apr 30 2020 at 17:06)</a>:</h4>
<p>need to investigate the code but yeah <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span> maybe that's the problem or something like that ... unsure</p>



<a name="195870890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870890">(Apr 30 2020 at 17:06)</a>:</h4>
<p>so imagine a case like <code>dyn Foo&lt;A&gt;</code></p>



<a name="195870900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870900">(Apr 30 2020 at 17:06)</a>:</h4>
<p>(no associated types)</p>



<a name="195870914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870914">(Apr 30 2020 at 17:06)</a>:</h4>
<p>the <code>Foo&lt;A&gt;</code> here is an <code>ExistentialTraitRef</code></p>



<a name="195870930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870930">(Apr 30 2020 at 17:06)</a>:</h4>
<p>that is, this is how it is represented</p>



<a name="195870955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870955">(Apr 30 2020 at 17:07)</a>:</h4>
<p>the impl for that is <a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L295" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L295">here</a></p>



<a name="195870997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195870997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195870997">(Apr 30 2020 at 17:07)</a>:</h4>
<p>and you can see that it <a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L305" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L305">invokes <code>relate_substs</code> with the second argument set to <code>None</code></a></p>



<a name="195871028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871028">(Apr 30 2020 at 17:07)</a>:</h4>
<p>this will cause the substs <a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L145" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L145">to be related with invariance</a></p>



<a name="195871041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871041">(Apr 30 2020 at 17:07)</a>:</h4>
<p>the point being---</p>



<a name="195871108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871108">(Apr 30 2020 at 17:08)</a>:</h4>
<p>whenever an "existential trait reference" like <code>Foo&lt;A&gt;</code> is related to another like <code>Foo&lt;B&gt;</code>, we require that <code>A = B</code></p>



<a name="195871149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871149">(Apr 30 2020 at 17:08)</a>:</h4>
<p>in other words, we want to inject invariance, but the question is <em>where does it come from</em>, in some sense</p>



<a name="195871197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871197">(Apr 30 2020 at 17:08)</a>:</h4>
<p>sorry, where does what comes from?</p>



<a name="195871215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871215">(Apr 30 2020 at 17:09)</a>:</h4>
<p>i.e., if we injected it when recursing in the <code>dyn</code> type, that would suggest that it's the keyword <code>dyn</code> that makes it invariant, but I think that's wrong. It's really most appropriate to inject it in the <code>ExistentialProjection</code> impl imo</p>



<a name="195871227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871227">(Apr 30 2020 at 17:09)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116266">Santiago Pastorino</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195871197" title="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195871197">said</a>:</p>
<blockquote>
<p>sorry, where does what comes from?</p>
</blockquote>
<p>the invariance</p>



<a name="195871245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871245">(Apr 30 2020 at 17:09)</a>:</h4>
<p>yeah <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="195871252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871252">(Apr 30 2020 at 17:09)</a>:</h4>
<p>i.e., is there some context where you have an <code>ExistentialProjection</code></p>



<a name="195871262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871262">(Apr 30 2020 at 17:09)</a>:</h4>
<p>where you would <em>want</em> to relate them with covariance</p>



<a name="195871268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871268">(Apr 30 2020 at 17:09)</a>:</h4>
<p>or whatever</p>



<a name="195871281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871281">(Apr 30 2020 at 17:09)</a>:</h4>
<p>as it happens, the "existential" types <em>only</em> appear in <code>dyn</code> right now</p>



<a name="195871284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871284">(Apr 30 2020 at 17:09)</a>:</h4>
<p>so it's sort of a moot point</p>



<a name="195871293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871293">(Apr 30 2020 at 17:09)</a>:</h4>
<p>but regardless I think the answer is no :)</p>



<a name="195871304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871304">(Apr 30 2020 at 17:09)</a>:</h4>
<p>trait matching and associated types are inherently invariant in rust right now</p>



<a name="195871332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871332">(Apr 30 2020 at 17:09)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="195871335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871335">(Apr 30 2020 at 17:09)</a>:</h4>
<p>so if we had some other kind of type that used the same concept, it should <em>still</em> be invariant</p>



<a name="195871416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871416">(Apr 30 2020 at 17:10)</a>:</h4>
<p>tl;dr I think these two calls should use "invariant" (<a href="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L253-L254" title="https://github.com/rust-lang/rust/blob/eece58a8e35c444afba6fa34873bc0244e32cd29/src/librustc_middle/ty/relate.rs#L253-L254">here</a>)</p>



<a name="195871449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871449">(Apr 30 2020 at 17:10)</a>:</h4>
<p>actually I think just doing that is probably the fix</p>



<a name="195871459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871459">(Apr 30 2020 at 17:10)</a>:</h4>
<p>so I can investigate where the invariance comes from and let you know before diving into a solution I guess</p>



<a name="195871467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871467">(Apr 30 2020 at 17:10)</a>:</h4>
<p>I said there were two bits of code but I think they both use this same core, "type-relating" visitor</p>



<a name="195871472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871472">(Apr 30 2020 at 17:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195871449" title="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195871449">said</a>:</p>
<blockquote>
<p>actually I think just doing that is probably the fix</p>
</blockquote>
<p>ahh well, :)</p>



<a name="195871512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871512">(Apr 30 2020 at 17:11)</a>:</h4>
<p>feel free to investigate, but I think that's the fix, the interesting question will be whether we start to encounter problems as a result of fixing the bug</p>



<a name="195871627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871627">(Apr 30 2020 at 17:12)</a>:</h4>
<p>hehe, yeah, you meant, more issues as part of fixing this problem?</p>



<a name="195871733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871733">(Apr 30 2020 at 17:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195871512" title="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195871512">said</a>:</p>
<blockquote>
<p>feel free to investigate, but I think that's the fix, the interesting question will be whether we start to encounter problems as a result of fixing the bug</p>
</blockquote>
<p>going to try to spend some time on this before throwing a fix because it will serve the purposes of understanding a bit the code there :)</p>



<a name="195871919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871919">(Apr 30 2020 at 17:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116266">Santiago Pastorino</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195871627" title="#narrow/stream/182449-t-compiler.2Fhelp/topic/variance.20and.20assoc.20types.20.2371550/near/195871627">said</a>:</p>
<blockquote>
<p>hehe, yeah, you meant, more issues as part of fixing this problem?</p>
</blockquote>
<p>I mean like</p>



<a name="195871926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871926">(Apr 30 2020 at 17:15)</a>:</h4>
<p>there's probably code relying on this</p>



<a name="195871954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871954">(Apr 30 2020 at 17:15)</a>:</h4>
<p>and we're going to break that code</p>



<a name="195871989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195871989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195871989">(Apr 30 2020 at 17:15)</a>:</h4>
<p>and what's worse, the code is probably reasonable -- i.e., a more sophisticated type system that incorporated some notion of variance into trait matching could accept it</p>



<a name="195872013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195872013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195872013">(Apr 30 2020 at 17:15)</a>:</h4>
<p>this is why I said this is P-criticial despite being old</p>



<a name="195872025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195872025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195872025">(Apr 30 2020 at 17:15)</a>:</h4>
<p>because the sooner we fix, the less of code like that we have to deal with</p>



<a name="195872177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195872177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195872177">(Apr 30 2020 at 17:17)</a>:</h4>
<p>ok, going to investigate a bit</p>



<a name="195872227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/variance%20and%20assoc%20types%20%2371550/near/195872227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/variance.20and.20assoc.20types.20.2371550.html#195872227">(Apr 30 2020 at 17:17)</a>:</h4>
<p>but after brewing a good <span aria-label="coffee" class="emoji emoji-2615" role="img" title="coffee">:coffee:</span>, first things first <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>